package com.example.ketangpai_backend.controller;

import com.example.ketangpai_backend.entity.User;
import com.example.ketangpai_backend.entity.param.UserParam;
import com.example.ketangpai_backend.service.UserService;
import com.example.ketangpai_backend.utils.JsonResult;
import org.springframework.web.bind.annotation.*;

@RequestMapping("/user")
@RestController
public class UserController {
    private UserService userService;

    public UserController(UserService userService) {
        this.userService = userService;
    }

    @PostMapping("/login")
    public JsonResult<?> login(@RequestBody UserParam userParam) throws Exception {
        User user=userService.login(userParam);
        return JsonResult.success(user,"登录成功");

    }
    @PostMapping("/create")
    public JsonResult<?> create(@RequestBody User user)throws Exception{
        boolean result=userService.create(user);
        if (result) {
            return JsonResult.success("注册成功");
        } else {
            return JsonResult.error("注册失败");
        }
    }
}
